package com.itboye.sunsun.wxapi;

import com.itboye.sunsun.R;
import com.itboye.sunsun.application.App;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {


	private IWXAPI api;
	public static String FinishQueRen="com.itboye.sunsun.querenzhifu";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pay_result);
		api = WXAPIFactory.createWXAPI(this, "wxa30658c4f4f6bbf4");
		api.registerApp("wxa30658c4f4f6bbf4");
		api.handleIntent(getIntent(), this);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq arg0) {
		// TODO Auto-generated method stub
	}

	@Override
	public void onResp(BaseResp resp) {
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			if(resp.errCode==0)
			{
				Toast.makeText(App.ctx, "支付成功", 0).show();
				this.finish();
				Intent intent=new Intent(FinishQueRen);
				sendBroadcast(intent);
			}else if(resp.errCode==-2)
			{
				Toast.makeText(App.ctx, "用户取消支付", 0).show();
				this.finish();
			}
			
		}
	}

}